﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using dhDataAcess.sysDAL;
using dhDataAcess.Model;
using dhDataAcess.dataAcess.stockDataSetTableAdapters ;
using dhDataAcess.dataAcess;
using dhDataAcess.baseBLL;
using dhDataAcess.produceDAL.Stock;
using dhDataAcess.produceLinq .StockLinq ;

namespace dhSystemBLL.produceBLL
{
 public    class StockMasterBLL
    {
     private stockMasterTableAdapter  _StockMasterAdapter = null;
     private stockMasterTableAdapter StockMasterAdapter
        {
            get
            {
                if (_StockMasterAdapter == null) _StockMasterAdapter = new stockMasterTableAdapter();
                return _StockMasterAdapter;
            }
        }
        /// <summary>
        /// 查询基础信息表
        /// </summary>
        /// <returns></returns>

     public stockDataSet.stockMasterDataTable getStockMasterAll()
        {
            try
            {
                return StockMasterAdapter.GetDatastockMasterALL ();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 查询基础信息表
        /// </summary>
        /// <returns></returns>

     public stockDataSet.stockMasterDataTable  getStockMasterAll(string pname)
        {
            try
            {
                return StockMasterAdapter.GetDatastockMasterBypname(pname);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }




        /// <summary>
        /// 基础信息插入
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
     public int StockMasterInsert(stockMasterModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                StockMasterDAL basList = new StockMasterDAL(tn, conn);
                basList.stockMasterInsert (row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

     public int StockMasterUpdate(stockMasterModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                StockMasterDAL basList = new StockMasterDAL(tn, conn);
                basList.stockMasterUpdate (row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="basNum"></param>
        /// <returns></returns>

        public int basListDel(string basNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                StockMasterDAL basList = new StockMasterDAL(tn, conn);
                basList.materialStockListDel (basNum);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
